home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utmisc1 / maprz2_e.lha / MapRZ2_EVD1_1 / Source / RetinaZ2mappedRE.asm < prev   
Assembly Source File  |  1996-03-27  |  9KB  |  431 lines

  1. *
  2. * ShapeShifter external video driver for Retina Z2
  3. *
  4. * $VER: RetinaZ2mappedRE.asm 1.0 (30.12.95)
  5. *
  6. * Christoph Niedeggen 24.12.95-30.12.95
  7. * based on code by Christian Bauer
  8.  
  9.         MACHINE    68020
  10.  
  11.         INCLUDE    "exec/types.i"
  12.         INCLUDE    "exec/macros.i"
  13.         INCLUDE    "exec/memory.i"
  14.         INCLUDE    "intuition/intuition.i"
  15.         INCLUDE    "utility/tagitem.i"
  16.         INCLUDE    "exec/alerts.i"
  17.         INCLUDE    "libraries/retina.i"
  18.         INCLUDE    "libraries/retinaemu.i"
  19.         INCLUDE    "libraries/retina_lib.i"
  20.         INCLUDE    "libraries/retinaemu_lib.i"
  21.         INCLUDE    "shapeextvideo.i"
  22.  
  23. *
  24. * Offset for linear mapped RetinaZ2 RAM
  25. *
  26.  
  27. C_RL_START    equ    $01c00000
  28.  
  29. *
  30. * Definition of our private context structure for storing local variables
  31. *
  32.  
  33.  STRUCTURE    MyContext,0
  34.     APTR    conIntuitionBase
  35.     APTR    conDOSBase
  36.     APTR    conRetinaBase
  37.     APTR    conRetinaEmuBase
  38.  
  39.     APTR    conScreen    ;The screen
  40.     APTR    conViewPort    ;The screen's ViewPort
  41.     APTR    conBitMap    ;The screen's RastPort
  42.     APTR    conRetinaScr    ;The screen's RetinaScreen
  43.  
  44.     STRUCT    conRGBBuf,256*3    ;Buffer for LoadRGB32
  45.  
  46.     WORD    conVideoMode    ;Video mode (VMODE_*)
  47.  LABEL    MyContext_SIZEOF
  48.  
  49. *
  50. * This is the driver header
  51. *
  52.  
  53.         EVHEADER DriverTags
  54.  
  55. *
  56. * The header tags that describe the driver and provide pointers to
  57. * the driver's routines
  58. *
  59.  
  60. DriverTags    dc.l    SHEV_Level,1        ;Interface level 1
  61.         dc.l    SHEV_Version,0
  62.         dc.l    SHEV_Revision,1
  63.         dc.l    SHEV_Name,DriverName
  64.         dc.l    SHEV_ID,DriverID
  65.         dc.l    SHEV_Author,DriverAuthor
  66.  
  67.         dc.l    SHEV_OpenScreen,MyOpenScreen
  68.         dc.l    SHEV_CloseScreen,MyCloseScreen
  69.         dc.l    SHEV_LoadRGB32,MyLoadRGB32
  70.         dc.l    SHEV_Refresh,MyRefresh
  71.         dc.l    TAG_END,0
  72.  
  73. DriverName    dc.b    "Retina Z2 mapped RetinaEmu Driver",0
  74.         CNOP    0,4
  75. DriverID    dc.b    "$VER: RetinaZ2mappedRE 1.0 (30.12.95)",13,10,0
  76.         CNOP    0,4
  77. DriverAuthor    dc.b    "Christoph Niedeggen",0
  78.         CNOP    0,4
  79.  
  80. *
  81. * The OpenScreen routine
  82. * a0: Taglist with input parameters
  83. * a1: Taglist with output parameters
  84. * a6: Base of utility.library
  85. *
  86.  
  87. MyOpenScreen    movem.l    d2-d7/a2-a6,-(sp)
  88.         move.l    a0,a4            ;a4: Input taglist
  89.         move.l    a1,a5            ;a5: Output taglist
  90.         move.l    a6,_UtilityBase
  91.         move.l    (4).w,_ExecBase
  92.  
  93. ; Allocate memory for context
  94.         move.l    _ExecBase,a6
  95.         move.l    #MyContext_SIZEOF,d0
  96.         move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  97.         JSRLIB    AllocVec
  98.         tst.l    d0
  99.         beq    OpenFailed
  100.         move.l    d0,a2            ;a2: Context
  101.  
  102. ; Open intuition.library
  103.         move.l    _ExecBase,a6
  104.         lea    IntuitionName,a1
  105.         moveq    #37,d0
  106.         JSRLIB    OpenLibrary
  107.         move.l    d0,conIntuitionBase(a2)
  108.         beq    OpenFailed
  109.  
  110. ; Open dos.library (for Delay())
  111.         move.l    _ExecBase,a6
  112.         lea    DOSName,a1
  113.         moveq    #37,d0
  114.         JSRLIB    OpenLibrary
  115.         move.l    d0,conDOSBase(a2)
  116.         beq    OpenFailed
  117.  
  118. ; Open retina.library
  119.         move.l    _ExecBase,a6
  120.         lea    RetinaName,a1
  121.         moveq    #0,d0
  122.         JSRLIB    OpenLibrary
  123.         move.l    d0,conRetinaBase(a2)
  124.         beq    OpenFailed
  125.  
  126. ; Open retinaemu.library
  127.         move.l    _ExecBase,a6
  128.         lea    RetinaEmuName,a1
  129.         moveq    #0,d0
  130.         JSRLIB    OpenLibrary
  131.         move.l    d0,conRetinaEmuBase(a2)
  132.         beq    OpenFailed
  133.  
  134. ; Store context pointer in output taglist
  135.         move.l    _UtilityBase,a6
  136.         move.l    a5,a0
  137.         move.l    #SHEV_Context,d0
  138.         JSRLIB    FindTagItem
  139.         move.l    d0,a0
  140.         move.l    a2,ti_Data(a0)
  141.  
  142. ; Get video mode and set the refresh type and screen depth accordingly
  143. ; This driver only supports VMODE_8BIT
  144.         move.l    _UtilityBase,a6
  145.         move.l    a4,a0
  146.         move.l    #SHEV_VideoMode,d0
  147.         moveq    #VMODE_1BIT,d1        ;Dummy default
  148.         JSRLIB    GetTagData
  149.         move.w    d0,conVideoMode(a2)
  150.  
  151.         cmp.l    #VMODE_8BIT,d0
  152.         bne    OpenFailed
  153.         move.l    a5,a0
  154.         move.l    #SHEV_RefreshType,d0
  155.         JSRLIB    FindTagItem
  156.         tst.l    d0
  157.         beq    10$
  158.         move.l    d0,a1
  159.         move.l    #RTYPE_CUSTOM,ti_Data(a1)    ;to get Vector at $8 patched
  160.         move.l    #8,ScrDepth
  161. 10$
  162.  
  163. ; Extract screen parameters from input taglist
  164.         move.l    _UtilityBase,a6
  165.         move.l    a4,a0
  166.         move.l    #SHEV_ScreenX,d0
  167.         moveq    #0,d1
  168.         JSRLIB    GetTagData
  169.         move.l    d0,ScrWidth
  170.  
  171.         move.l    a4,a0
  172.         move.l    #SHEV_ScreenY,d0
  173.         moveq    #0,d1
  174.         JSRLIB    GetTagData
  175.         move.l    d0,ScrHeight
  176.  
  177.         move.l    a4,a0
  178.         move.l    #SHEV_DisplayID,d0
  179.         moveq    #0,d1
  180.         JSRLIB    GetTagData
  181.         move.l    d0,ScrDisplayID
  182.  
  183.         move.l    a4,a0
  184.         move.l    #SHEV_OverscanType,d0
  185.         moveq    #OSCAN_TEXT,d1
  186.         JSRLIB    GetTagData
  187.         move.l    d0,ScrOverscan
  188.  
  189. ; Open the screen and store pointer in output taglist
  190.  
  191.         move.l    conIntuitionBase(a2),a6    ;4 or 8 Bit
  192.         sub.l    a0,a0
  193.         lea    ScreenTags,a1
  194.         JSRLIB    OpenScreenTagList
  195.         move.l    d0,a3            ;a3: Screen
  196.         move.l    d0,conScreen(a2)
  197.         beq    OpenFailed
  198.         bra    ScreenOpened
  199.  
  200. ScreenOpened    move.l    _UtilityBase,a6
  201.         move.l    a5,a0
  202.         move.l    #SHEV_Screen,d0
  203.         JSRLIB    FindTagItem
  204.         move.l    d0,a0
  205.         move.l    a3,ti_Data(a0)
  206.  
  207. ; Wait a bit (retinaemu seems to need this)
  208.         move.l    conDOSBase(a2),a6
  209.         moveq    #15,d1
  210.         JSRLIB    Delay
  211.  
  212. ; Extract our private data
  213.         lea    sc_ViewPort(a3),a0
  214.         move.l    a0,conViewPort(a2)
  215.         lea    sc_RastPort(a3),a0
  216.         move.l    rp_BitMap(a0),conBitMap(a2)
  217.  
  218. ; Did it open on the Retina card?
  219.         move.l    conRetinaEmuBase(a2),a6
  220.         move.l    conBitMap(a2),a0
  221.         jsr    _LVORE_GetRetinaScreen(a6)
  222.         move.l    d0,conRetinaScr(a2)
  223.         beq    OpenFailed
  224.  
  225. ; Extract all the other data that the caller wants
  226.         move.l    _UtilityBase,a6
  227.         move.l    a5,a0
  228.         move.l    #SHEV_ScreenBase,d0
  229.         JSRLIB    FindTagItem
  230.         tst.l    d0
  231.         beq    1$
  232.         move.l    d0,a1
  233.         move.l    conRetinaScr(a2),a0
  234.         move.l    _rs_BitMap(a0),a0
  235. ;        move.l    conRetinaBase(a2),a6
  236. ;        jsr    _LVORetina_SetSegmentPtr(a6)    ;Preserves a1
  237.         move.l    a0,d0
  238.         add.l    #C_RL_START,d0            ;CN24.12.95
  239.         move.l    d0,ti_Data(a1)
  240. 1$
  241.         move.l    _UtilityBase,a6
  242.         move.l    a5,a0
  243.         move.l    #SHEV_BytesPerRow,d0
  244.         JSRLIB    FindTagItem
  245.         tst.l    d0
  246.         beq    2$
  247.         move.l    d0,a1
  248.         move.l    conRetinaScr(a2),a0
  249.         moveq    #0,d0
  250.         move.w    _rs_Modulo(a0),d0
  251.         move.l    d0,ti_Data(a1)
  252. 2$
  253.  
  254. ; Everything is OK
  255.         movem.l    (sp)+,d2-d7/a2-a6
  256.         moveq    #0,d0
  257.         rts
  258.  
  259. ; An error occurred
  260. OpenFailed    movem.l    (sp)+,d2-d7/a2-a6
  261.         moveq    #-1,d0
  262.         rts
  263.  
  264. *
  265. * The CloseScreen routine
  266. * a0: Taglist with input parameters
  267. * a1: Taglist with output parameters
  268. * a2: Context pointer (never NULL)
  269. * a6: Base of utility.library
  270. *
  271.  
  272. MyCloseScreen    movem.l    d2-d7/a2-a6,-(sp)
  273.  
  274. ; Close the screen
  275.         move.l    conScreen(a2),d0
  276.         beq    1$
  277.         cmp.w    #VMODE_8BIT,conVideoMode(a2)
  278.         bne    11$
  279.         move.l    d0,a0            ;8 Bit
  280.         move.l    conIntuitionBase(a2),a6
  281.         JSRLIB    CloseScreen
  282.         bra    1$
  283. 11$        move.l    d0,a0            ;16/24 Bit
  284.         move.l    conRetinaEmuBase(a2),a6
  285.         jsr    _LVORE_CloseDeepScreen(a6)
  286. 1$
  287.  
  288. ; Close retinaemu.library
  289.         move.l    conRetinaEmuBase(a2),d0
  290.         beq    2$
  291.         move.l    d0,a1
  292.         move.l    _ExecBase,a6
  293.         JSRLIB    CloseLibrary
  294. 2$
  295.  
  296. ; Close retina.library
  297.         move.l    conRetinaBase(a2),d0
  298.         beq    3$
  299.         move.l    d0,a1
  300.         move.l    _ExecBase,a6
  301.         JSRLIB    CloseLibrary
  302. 3$
  303.  
  304. ; Close dos.library
  305.         move.l    conDOSBase(a2),d0
  306.         beq    4$
  307.         move.l    d0,a1
  308.         move.l    _ExecBase,a6
  309.         JSRLIB    CloseLibrary
  310. 4$
  311.  
  312. ; Close intuition.library
  313.         move.l    conIntuitionBase(a2),d0
  314.         beq    6$
  315.         move.l    d0,a1
  316.         move.l    _ExecBase,a6
  317.         JSRLIB    CloseLibrary
  318. 6$
  319.  
  320. ; Free context
  321.         move.l    _ExecBase,a6
  322.         move.l    a2,a1
  323.         JSRLIB    FreeVec
  324.  
  325. CloseDone    movem.l    (sp)+,d2-d7/a2-a6
  326.         moveq    #0,d0
  327.         rts
  328.  
  329. *
  330. * The LoadRGB32 routine
  331. * a0: Taglist with input parameters
  332. * a1: Taglist with output parameters
  333. * a2: Context pointer
  334. * a6: Base of utility.library
  335. *
  336.  
  337. ; Get pointer to 32 bit color table
  338. MyLoadRGB32    movem.l    d2-d7/a2-a6,-(sp)
  339.         move.l    a0,a4        ;a4: Input taglist
  340.         move.l    #SHEV_ColorTable,d0
  341.         moveq    #0,d1
  342.         JSRLIB    GetTagData
  343.         move.l    d0,a0        ;a0: Color table
  344.  
  345. ; Convert to 8 bit color table
  346.         lea    conRGBBuf(a2),a1
  347.         move.w    #256*3-1,d1
  348. 1$        move.l    (a0)+,d0
  349.         rol.l    #8,d0
  350.         move.b    d0,(a1)+
  351.         dbra    d1,1$
  352.  
  353. ; Activate palette
  354.         move.l    conRetinaBase(a2),a6
  355.         move.l    conRetinaScr(a2),a0
  356.         moveq    #0,d0        ;Start with color #0
  357.         move.l    #256,d1        ;Load 256 colors
  358.         lea    conRGBBuf(a2),a1
  359.         jsr    _LVORetina_LoadPalette(a6)
  360.  
  361.         movem.l    (sp)+,d2-d7/a2-a6
  362.         moveq    #0,d0
  363.         rts
  364.  
  365.  
  366. MyRefresh    movem.l    a5-a6,-(sp)
  367.  
  368.         move.l    (4).w,a6
  369.         lea    setVBR(pc),a5
  370.         jsr    -$001e(a6)            ;Supervisor()
  371.  
  372.         movem.l    (sp)+,a5-a6
  373.         rts
  374.  
  375. setVBR        movec.l    VBR,a0
  376.         move.l    $8(a0),$8
  377.         rte
  378.  
  379. *
  380. * Constants
  381. *
  382.  
  383. ; Library names
  384. IntuitionName    dc.b    "intuition.library",0
  385. DOSName        dc.b    "dos.library",0
  386. RetinaName    dc.b    "retina.library",0
  387. RetinaEmuName    dc.b    "retinaemu.library",0
  388.  
  389. ; The name of our screen
  390. ScreenName    dc.b    "ShapeShifter Screen",0
  391.         CNOP    0,4
  392.  
  393. *
  394. * Data section
  395. *
  396.  
  397.         SECTION    "DATA",DATA
  398.  
  399. ; Taglist for OpenScreen()
  400. ; Note that it's only safe to use this structure here because
  401. ;  the SHEV_OpenScreen routine is guaranteed not to be called
  402. ;  more than once at a time. The buffer for LoadRGB32, however,
  403. ;  is declared in the Context and not in the BSS segment because
  404. ;  that routine may be called multiple times for multiple
  405. ;  screens.
  406. ScreenTags    dc.l    SA_Depth
  407. ScrDepth    dc.l    0
  408.         dc.l    SA_Width
  409. ScrWidth    dc.l    0
  410.         dc.l    SA_Height
  411. ScrHeight    dc.l    0
  412.         dc.l    SA_DisplayID
  413. ScrDisplayID    dc.l    0
  414.         dc.l    SA_Overscan
  415. ScrOverscan    dc.l    0
  416.         dc.l    SA_Quiet,-1
  417.         dc.l    SA_Title,ScreenName
  418.         dc.l    TAG_END,0
  419.  
  420. *
  421. * BSS section
  422. *
  423.  
  424.         SECTION    "BSS",BSS
  425.  
  426. ; Library base pointers
  427. _ExecBase    ds.l    1
  428. _UtilityBase    ds.l    1
  429.  
  430.         END
  431.